package com.cyys.modules.generator.controller;

import com.cyys.common.ql.AR;
import com.cyys.modules.core.controller.BaseAction;
import com.cyys.modules.core.sysParam.ParamBasicUtil;
import com.cyys.modules.core.sysParam.ParamConstants;
import com.cyys.modules.generator.model.GeneratorConfigure;
import com.cyys.modules.generator.service.GeneratorConfigureService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/generator/configure")
public class GeneratorConfigureAction extends BaseAction {

	@Resource
	private GeneratorConfigureService generatorConfigureService;

	@GetMapping("/edit/inputMain")
	@RequiresPermissions("generator:configure:edit")
	public String inputMain(Model model) {
		model.addAttribute("nameCaseTypeMap", ParamBasicUtil.getParamBasicTypeMap().get(ParamConstants.NAME_CASE_TYPE));
		model.addAttribute("tinyintTransTypeMap", ParamBasicUtil.getParamBasicTypeMap().get(ParamConstants.TINYINT_TRANS_TYPE));
		model.addAttribute("generatorConfigure", generatorConfigureService.getById("1"));
		return "module/generator/configure/generatorConfigure-input";
	}

	@ResponseBody
	@PostMapping("/edit/save")
	@RequiresPermissions(value = "generator:configure:edit")
	public AR edit(GeneratorConfigure generatorConfigure) {
		return generatorConfigureService.update(generatorConfigure);
	}

}
